package com.example.demo.service.serviceImpl;

import com.example.demo.service.cacheAPIService;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

public class cacheAPIServiceImpl implements cacheAPIService {

    @Override
    public void addEhcacheElement(String key, Object value, Cache cache) {
        //创建元素
        Element element=new Element(key,value);

        //将元素添加到缓存
        cache.put(element);
    }

    @Override
    public Boolean removeElementByKey(String key, Cache cache) {
        cache.remove(key);
        if(selectValueByKey(key,cache)==null){
            return true;
        }
        return false;
    }

    @Override
    public Object selectValueByKey(String key, Cache cache) {
        //        获取缓存,并返回
        Element result=cache.get(key);
        return result;
    }
}
